package com.zk.algorithm.array;

import com.zk.algorithm.Utils;
import com.zk.algorithm.annotation.Easy;
import com.zk.algorithm.annotation.Finished;
import com.zk.algorithm.annotation.LeetCodeExplore;

/**
 * @author zk
 */
@LeetCodeExplore
@Easy
@Finished
public class SingleNumber {

    public int singleNumber(int[] nums) {
        int ans = nums[0];

        for (int i = 1; i < nums.length; i++) {
            ans ^= nums[i];
        }

        return ans;
    }

    public static void main(String...args) {
        Utils.println(new SingleNumber().singleNumber(new int[] {
                4,1,2,1,2
        }));

        Utils.println(new SingleNumber().singleNumber(new int[] {
                2,2,1
        }));
    }

}
